#include<bits/stdc++.h>
#define FILE_NAME "detect"
#define fre 1
using namespace std;
typedef long long ll;
//vv XianSu
int n,m,l,vv,d[100010],v[100010],a[100010],p[100010];
bool cat[100010];
bool cs[100010];
ll ans2=9999999;
vector<int>detect[100010],de[100010];
//Cong d_i ShiRu.
//ChuShi SuDu v_i
//JiaSuDu a_i
//CeSuYi WeiZhi p_i
void dfs(int dep,bool choose,ll sum){
    if(dep>m){
        bool flag=1;
        for(int i=1;i<=n;i++){
            if(cs[i]!=cat[i]){
                flag=0;
                break;
            }
        }
        if(flag) ans2=min(ans2,sum);
        return;
    }
    if(choose){
        sum++;
        for(int i=0;i<detect[dep].size();i++){
            cat[detect[dep][i]]=1;
        }
    }
    dfs(dep+1,0,sum);
    dfs(dep+1,1,sum);
    if(choose){
        for(int i=0;i<detect[dep].size();i++){
            cat[detect[dep][i]]=0;
        }
        sum--;
    }
    return;
}
void solve(){
    memset(cat,0,sizeof(cat));
    memset(cs,0,sizeof(cs));
    ans2=9999999;
    cin>>n>>m>>l>>vv;
    for(int i=1;i<=n;i++){
        cin>>d[i]>>v[i]>>a[i];
        de[i].clear();
    }
    for(int i=1;i<=m;i++){
        cin>>p[i];
        detect[i].clear();
    }
    for(int i=1;i<=n;i++){
        if(v[i]<=vv&&a[i]<=0){
            continue;
        }
        else if(v[i]>vv&&a[i]>=0){
            cs[i]=1;
            for(int j=1;j<=m;j++){
                if(p[j]>=d[i]){
                    detect[j].push_back(i);
                    de[i].push_back(j);
                }
            }
            continue;
        }
        else{
            if(v[i]<=vv&&a[i]>0){
                double s=(pow(vv,2)-pow(v[i],2))/(2*a[i]);
                for(int j=1;j<=m;j++){
                    if(p[j]>=d[i]+s){
                        cs[i]=1;
                        detect[j].push_back(i);
                        de[i].push_back(j);
                    }
                }
                continue;
            }
            if(v[i]>vv&&a[i]<0){
                double s=(pow(vv,2)-pow(v[i],2))/(2*a[i]);
                for(int j=1;j<=m;j++){
                    if(p[j]>=d[i]&&p[j]<d[i]+s){
                        cs[i]=1;
                        detect[j].push_back(i);
                        de[i].push_back(j);
                    }
                }
                continue;
            }
        }
    }
    ll ans1=0;
    for(int i=1;i<=n;i++){
        if(cs[i]){
            ans1++;
        }
    }
    dfs(0,0,0);
    cout<<ans1<<" "<<m-ans2<<endl;
}
int main(){
#ifdef fre
    freopen(FILE_NAME ".in","r",stdin);
    freopen(FILE_NAME ".out","w",stdout);
#endif
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int T;
    cin>>T;
    while(T--){
        solve();
    }
#ifdef fre
    fclose(stdin);
    fclose(stdout);
#endif
    return 0;
}